package com.example.Laboratory.Controller;

import com.example.Laboratory.Entity.Friendship;
import com.example.Laboratory.Service.FriendshipService;
import com.example.Laboratory.Untils.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;

@RestController
@Api(value = "Friendship", description = "友站链接")
@RequestMapping(value = "/friendship")
@CrossOrigin
public class FriendshipController {

    @Autowired
    FriendshipService friendshipService;

    @ApiOperation(value = "添加友站链接", notes = "添加友站链接")
    @RequestMapping(value = "/addFriendship", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object addFriendship (Friendship t) throws IOException {
        return ResultCode.SUCCESS.result(friendshipService.addFriendship(t));
    }

    @ApiOperation(value = "删除友站链接", notes = "删除友站链接")
    @RequestMapping(value = "/deleteFriendship", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    public Object deleteFriendship (@RequestParam int friendship_id) throws IOException {
        return ResultCode.SUCCESS.result(friendshipService.deleteFriendship(friendship_id));
    }

    @ApiOperation(value = "查找友站链接", notes = "查找友站链接")
    @RequestMapping(value = "/researchFriendship", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object selectFriendship ( ) throws IOException {
        return ResultCode.SUCCESS.result(friendshipService.selectFriendship());
    }

    @ApiOperation(value = "修改友站链接", notes = "修改友站链接")
    @RequestMapping(value = "/reviseFriendship", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object updateFriendship (Friendship i) throws IOException {
        return ResultCode.SUCCESS.result(friendshipService.updateFriendship(i));
    }
}